window.onload=function() {
    // 账户设置隐藏显示
    // 第一页
    var header_hidden = document.querySelector(".header-hidden");
    var number_fit = document.querySelector(".header-box-1").children[1];
    var q = document;
    number_fit.addEventListener("mouseover", function () {
        header_hidden.style.display = "block";
    });
    q.addEventListener("click", function () {
        header_hidden.style.display = "none";
    });
    header_hidden.addEventListener("click", function (e) {
        e.stopPropagation();
    })

    // // 点击收货地址跳转
    var address_1=document.querySelector(".user-news-box-1-1");
    address_1.addEventListener("click",function(){
        window.location.href="/addressPage";
    });
    // 跳转到首页
    var all_main=document.querySelector(".nav-top-box-1").children[0]
    all_main.addEventListener("click", function () {
        window.location.href="/";
    });
    // 跳转到用户界面首页
    var main = document.querySelector(".header-box-1").children[0];
    main.addEventListener("click",function(){
        window.location.href="/User/userInterface"
    })// 跳转到登录页面或者个人中心
    var nav_top_box_2=document.querySelector(".nav-top-box-2").children[0];
    var text_1=nav_top_box_2.innerHTML;
    nav_top_box_2.addEventListener("click",function() {
        if (text_1 == "登录") {
            window.location.href = "/User/login";
        } else {
            window.location.href = "/User/userInterface";
        }
    })
    //点击退出跳转到主页
    var exit = document.querySelector(".exit")
    exit.addEventListener("click",function(){
        $.ajax({
            type: "post",
            url: "/User/loginOut",
            // data: {
            // },
            success: function (data) {
                // alert("退出")
                window.location.href="/";

            },error: function () {
                console.log("調取接口失敗")
            }
        })
    });
    // 点击个人资料跳转基础资料
    var userin=document.querySelector(".main-left").children[2];
    userin.onclick=function () {
        window.location.href = "/User/userInformation";
    }
    // 点击修改密码
    function change(x) {
        var change = document.querySelector(".change");
        change.addEventListener("click",function(){
            var newpassword = document.querySelector(".new-password");
            var oldpassword = document.querySelector(".old-password");
            var newpassword1 = document.querySelector(".new-again");
            if(newpassword1.value==newpassword.value) {
                $.ajax({
                    type: "post",
                    url: "/User/updatePassword",
                    data: {
                        newpassword: newpassword.value,
                        password: oldpassword.value,
                        userId: x
                    },
                    success: function (data) {
                        if (data == 1) {
                            alert("修改成功");
                        } else if (data == 0) {
                            alert("修改失败")
                        } else if (data == 2) {
                            alert("输入密码长度不够")
                        }
                        console.log(oldpassword.value)
                    }
                })
            }else{
                alert("不一致")
            }

        })
    }
    var userID=document.querySelector(".userID");
    if(userID.innerHTML=="用户名"){
        userID.style.display="none"
    }else {
        userID.style.display = "none"
        change(userID.innerHTML);
    }
}